#ifndef _SERVICECORE_SERVICE_H
#define _SERVICECORE_SERVICE_H

#include "IServiceManager.h"

struct auto_service_provider_registration{
	auto_service_provider_registration(const String& service,vclsid clsidServiceProvider){
		sys::ObjectPtr objServiceManager;
		VRVERIFY(objServiceManager.CreateObject(CLSID_ServiceManager));
		sys::InterfacePtr<IServiceManager> pIFServiceManager(objServiceManager);
		pIFServiceManager->RegisterServiceProvider(service,clsidServiceProvider);
	}
};
#ifndef AUTO_REGISTER_SERVICE_PROVIDER
#define AUTO_REGISTER_SERVICE_PROVIDER(service,service_provider_class)\
	static auto_service_provider_registration _auto_register##service_provider_class##(service,service_provider_class::CLSID_CLS);
#endif

namespace sys{
	template<typename TServiceInterface>
	struct ServiceInterfacePtr : public InterfacePtr<TServiceInterface>
	{
		explicit ServiceInterfacePtr(const String& service)
		{
			sys::ObjectPtr objServiceManager;
			VRVERIFY(objServiceManager.CreateObject(CLSID_ServiceManager));
			sys::InterfacePtr<IServiceManager> pIFServiceManager(objServiceManager);
			IObject* pServiceProviderObj = pIFServiceManager->GetServiceProvider(service);
			QueryVInterface(pServiceProviderObj);
		}
	};
}

#endif//_SERVICECORE_SERVICE_H